// PROGRAMA : CTLPC006 OPCA: 'ELD'
// BIBLIOTECA : PRODETR
// SISTEMA : INFORMACOES DE SEGURANCA PUBLICA - SISP
// CLIENTE : SEJUSP - SEC. DA JUSTICA E SEGURANCA PUBLICA
// INSTITUTO DE IDENTIFICACAO, DETRAN E SEFAZ
// PROGRAMADOR : EDU/FM DATA: 18/10/97
// OBJETIVO : CONSULTA CEDULA ID. EMITIDAS COPY: CTLCC001
// ATUALIZACOES DATA
// PROGRAMA : CTLPC006 24/11/1997
// BIBLIOTECA : PRODETR
// PROGRAMADOR : COELHO
// OBJETIVO : ADAPTACAO PARA O SHOPPING DO CIDADAO (P200)
// : ALTERACAO DE TELA E DAS DATAS (N6) PARA (N8)
package br.com.vti.sisp_sicrim.antigo.controller.programa;

import java.text.ParseException;
import java.util.Arrays;

import net.sf.jasperreports.engine.JRException;

import org.apache.commons.lang3.StringUtils;

import br.com.caelum.vraptor.Post;
import br.com.caelum.vraptor.Path;
import br.com.caelum.vraptor.Resource;
import br.com.caelum.vraptor.Result;
import br.com.caelum.vraptor.interceptor.download.InputStreamDownload;
import br.com.vti.sisp_sicrim.antigo.controller.relatorios.Ctltc106Report;
import br.com.vti.sisp_sicrim.antigo.controller.tela.Ctlpc006A;
import br.com.vti.sisp_sicrim.antigo.controller.tela.Ctlpc006B;
import br.com.vti.sisp_sicrim.antigo.controller.tela.Ctlpc006C;
import br.com.vti.sisp_sicrim.antigo.controller.tela.Ctlpc006D;
import br.com.vti.sisp_sicrim.antigo.controller.tela.Ctltc001;
import br.com.vti.sisp_sicrim.antigo.controller.tela.Ctltc006;
import br.com.vti.sisp_sicrim.antigo.model.DidCadastro;
import br.com.vti.sisp_sicrim.antigo.model.SicControle;
import br.com.vti.sisp_sicrim.antigo.model.SicTabelas;
import br.com.vti.sisp_sicrim.antigo.model.Sisldat8;
import br.com.vti.sisp_sicrim.antigo.model.Sisll001;
import br.com.vti.sisp_sicrim.antigo.util.ExceptionProgram;
import br.com.vti.sisp_sicrim.antigo.util.Sessao;
import br.com.vti.sisp_sicrim.antigo.util.Sisgsisp;
import br.com.vti.sisp_sicrim.antigo.util.UtilBean;

/**
 * Classe : Ctlpc006 OBJETIVO : CONSULTA CEDULA ID. EMITIDAS COPY: CTLCC001 *
 * 
 * @author Incode - Data: mai/2014
 * 
 */
@Resource
@Path("/antigo/ctlpc006")
public class Ctlpc006 {
	// Views utilizadas
	SicControle vwDvecon = new SicControle();
	SicControle vwDvecon2 = new SicControle();
	// vwDvecad = new;
	DidCadastro vwDidcad = new DidCadastro();
	SicTabelas vwTabele = new SicTabelas();
	// dvecad = new;
	// Telas/relatorios utilizados
	Ctlpc006A ctlpc006A;
	Ctlpc006B ctlpc006B;
	Ctlpc006C ctlpc006C;
	Ctlpc006D ctlpc006D;
	Ctltc001 ctltc001;
	Ctltc006 ctltc006;
	Ctltc106Report report;
	// Includes utilizados
	Sisldat8 sisldat8 = new Sisldat8();
	Sisll001 sisll001 = new Sisll001();
	// Areas globais / session
	Sisgsisp sisgsisp;
	// Funcoes/subrotinas
	FuncoesGerais funcoes = new FuncoesGerais();

	Result result;
	Sessao sessao;
	Boolean primeiraVez = false;
	Ctlpc006 ctlpc006Anterior;
	String faseproc = "0";

	private int opc = 0;
	private String chave = "";
	private int i = 0;
	private int cont = 0;
	private long valpago = 0;
	private long[] nde = new long[15];
	private int[] mat = new int[15];
	private long[] rg1 = new long[51];
	private long[] nde1 = new long[51];
	private int[] mat1 = new int[51];
	private String[] conimp = new String[3];
	private int[] dat1 = new int[51];
	private String[] nom1 = new String[51];
	private String chassi = "";
	private int datn = 0;
	private InputStreamDownload relatorio;

	private Ctlpc006A preMapas() {
		ctlpc006A = new Ctlpc006A(true, sessao);
		ctlpc006B = new Ctlpc006B(true, sessao);
		ctlpc006C = new Ctlpc006C(true, sessao);
		ctlpc006D = new Ctlpc006D(true, sessao);
		ctltc001 = new Ctltc001(true, sessao);
		ctltc006 = new Ctltc006(true, sessao);

		ctlpc006A.setNavegar("../ctlpc006/executar");
		ctlpc006B.setNavegar("../ctlpc006/executar");
		ctlpc006C.setNavegar("../ctlpc006/executar");
		ctlpc006D.setNavegar("../ctlpc006/executar");
		ctltc001.setNavegar("../ctlpc006/executar");
		ctltc006.setNavegar("../ctlpc006/executar");

		Arrays.fill(nde, 0);
		Arrays.fill(mat, 0);
		Arrays.fill(rg1, 0);
		Arrays.fill(nde1, 0);
		Arrays.fill(mat1, 0);
		Arrays.fill(conimp, "");
		Arrays.fill(dat1, 0);
		Arrays.fill(nom1, "");
		ctltc001.setDataCorrente(UtilBean.obtemDataDia());
		ctlpc006A.setDataCorrente(UtilBean.inverteDataCorrente());
		datn = UtilBean.obtemDataCorrente();
		// Par�grafo: r0()
		return ctlpc006A;
	}

	public Ctlpc006(Result result, Sessao sessao) {
		this.result = result;
		this.sessao = sessao;
	}

	@Post
	public InputStreamDownload executar(Ctlpc006A ctlpc006A, Ctlpc006B ctlpc006B, Ctlpc006C ctlpc006C, Ctlpc006D ctlpc006D, Ctltc001 ctltc001, Ctltc006 ctltc006) {
		try {
			main(ctlpc006A, ctlpc006B, ctlpc006C, ctlpc006D, ctltc001, ctltc006);
		} catch (Exception e) {
			ExceptionProgram excp = new ExceptionProgram();
			excp.trataErroSiscerro(e, sessao, this.getClass().getSimpleName());
		}

		return relatorio;
	}

	private void main(Ctlpc006A pctlpc006A, Ctlpc006B pctlpc006B, Ctlpc006C pctlpc006C, Ctlpc006D pctlpc006D, Ctltc001 pctltc001, Ctltc006 pctltc006) throws Exception {
		if (pctlpc006A == null && pctlpc006B == null && pctlpc006C == null && pctlpc006D == null && pctltc001 == null && pctltc006 == null) {
			primeiraVez = true;
			// ctltc006 = new Ctltc006 (primeiraVez);
			ctlpc006A = preMapas();
			ctlpc006A.setNavegar("../ctlpc006/executar");
			result.include("ctlpc006A", ctlpc006A);
			sessao.setAtributo("CTLPC006", this);
			ctlpc006A.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
			return;
		} else {
			restaurarEstados(pctlpc006A, pctlpc006B, pctlpc006C, pctlpc006D, pctltc001, pctltc006);
		}

		if (pctltc001 != null && pctltc001.getFuncao().equals(UtilBean.ctt_retorna)) {
			ctlpc006A.enviarMensagem(null, "");
			result.include("ctlpc006A", ctlpc006A);
			sessao.setAtributo("CTLPC006", this);
			ctlpc006A.enviarTela(false, result, getClass().getSimpleName().toUpperCase());
			return;
		}
		if (pctlpc006B != null && pctlpc006B.getFuncao().equals(UtilBean.ctt_retorna)) {
			ctlpc006A.enviarMensagem(null, "");
			result.include("ctlpc006A", ctlpc006A);
			sessao.setAtributo("CTLPC006", this);
			ctlpc006A.enviarTela(false, result, getClass().getSimpleName().toUpperCase());
			return;
		}

		if (pctltc006 != null && pctltc006.getFuncao().equals(UtilBean.ctt_retorna)) {
			ctltc006.setMensagem("");
			sessao.setAtributo("CTLPC006", this);
			result.include("ctltc006", ctltc006);
			ctltc006.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
			return;
		}

		if (ctltc006.getConf().equals("N")) {
			preMapas();
			ctlpc006A.enviarMensagem(null, "");
			result.include("ctlpc006A", ctlpc006A);
			sessao.setAtributo("CTLPC006", this);
			ctlpc006A.enviarTela(false, result, getClass().getSimpleName().toUpperCase());
			return;
		}

		// DEFINE PRINTER(FM = 1)

		// ctltc006.setConf("S");

		if (pctlpc006A != null) {
			ctlpc006A.receberTela(false, result);
		}
		if (!UtilBean.funcao.equals(UtilBean.ctt_processa)) {
			ctlpc006A.enviarMensagem(null, "");
			result.include("ctlpc006A", ctlpc006A);
			sessao.setAtributo("CTLPC006", this);
			ctlpc006A.enviarTela(false, result, getClass().getSimpleName().toUpperCase());
			return;
		}
		if (!ctltc001.getOperacao().equals("ELD")) {
			testar();
		}

		if (!UtilBean.validarMascara(ctlpc006A.getDatini(), "yyyyMMdd")) {
			ctlpc006A.enviarMensagem("operacao", "");
			result.include("ctlpc006A", ctlpc006A);
			sessao.setAtributo("CTLPC006", this);
			ctlpc006A.enviarTela(false, result, getClass().getSimpleName().toUpperCase());
			return;
		}
		if (!UtilBean.validarMascara(ctlpc006A.getDatfim(), "yyyyMMdd")) {
			ctlpc006A.enviarMensagem("adt", "");
			result.include("ctlpc006A", ctlpc006A);
			sessao.setAtributo("CTLPC006", this);
			ctlpc006A.enviarTela(false, result, getClass().getSimpleName().toUpperCase());
			return;
		}
		if (Integer.parseInt(ctlpc006A.getDatini()) > Integer.parseInt(ctlpc006A.getDatfim())) {
			ctlpc006A.enviarMensagem("operacao", "");
			result.include("ctlpc006A", ctlpc006A);
			sessao.setAtributo("CTLPC006", this);
			ctlpc006A.enviarTela(false, result, getClass().getSimpleName().toUpperCase());
			return;
		}
		if (ctlpc006A.getTidoem() == 81 || ctlpc006A.getTidoem() == 82 || ctlpc006A.getTidoem() == 87 || ctlpc006A.getTidoem() == 88) {
			ctlpc006B.setTidoem(ctlpc006A.getTidoem());
		}
		if (!(ctlpc006B.getTidoem() == 81 || ctlpc006B.getTidoem() == 82 || ctlpc006B.getTidoem() == 87 || ctlpc006B.getTidoem() == 88)) {

			if (!ctlpc006B.getEnviada()) {
				sessao.setAtributo("CTLPC006", this);
				result.include("ctlpc006B", ctlpc006B);
				ctlpc006B.enviarTela(false, result, getClass().getSimpleName().toUpperCase());
				return;
			}
			if (pctlpc006B != null) {
				ctlpc006B.receberTela(false, result);
			}
			if (UtilBean.funcao.equals(UtilBean.ctt_retorna)) {
				result.include("ctlpc006A", ctlpc006A);
				sessao.setAtributo("CTLPC006", this);
				ctlpc006A.enviarTela(false, result, getClass().getSimpleName().toUpperCase());
				return;
			}
			if (!(ctlpc006B.getTidoem() == 81 || ctlpc006B.getTidoem() == 82 || ctlpc006B.getTidoem() == 87 || ctlpc006B.getTidoem() == 88)) {
				ctlpc006A.enviarMensagem(null, "INFORME OS CODIGOS ACIMA");
				result.include("ctlpc006A", ctlpc006A);
				sessao.setAtributo("CTLPC006", this);
				ctlpc006A.enviarTela(false, result, getClass().getSimpleName().toUpperCase());
				return;
			}
			// continue;
		}

		if (ctlpc006A.getTidoem() == 81 || ctlpc006A.getTidoem() == 82 || ctlpc006A.getTidoem() == 87 || ctlpc006A.getTidoem() == 88) {
			ctlpc006A.setTidoem(ctlpc006A.getTidoem());
		}

		switch (ctlpc006B.getTidoem()) {
		case 81: {
			ctltc006.setTitulo("ATESTADO DE ANTECEDENTES EMITIDO");
			break;
		}
		case 82: {
			ctltc006.setTitulo("ATESTADO DE ANTECEDENTES CANCELADO");
			break;
		}
		case 87: {
			ctltc006.setTitulo("CARTEIRA DE IDENTIDADE CACELADA");
			break;
		}
		case 88: {
			ctltc006.setTitulo("CARTEIRA DE IDENTIDADE EMITIDA ");
			break;
		}
		default: {
			break;
		}
		}
		if (ctlpc006B.getTidoem() == 81 || ctlpc006B.getTidoem() == 88) {
			vwTabele.pesq = UtilBean.moveSubstring(vwTabele.pesq, 0, 3, "N", 207);
			vwTabele.pesq = UtilBean.moveSubstring(vwTabele.pesq, 3, 12, "N", ctlpc006A.getNumpos());
			vwTabele.resp = funcoes.sisst001(207, ctlpc006A.getNumpos(), vwTabele.resp);
			if (UtilBean.subStr(vwTabele.resp, 0, 1).equals("#")) {
				ctlpc006A.enviarMensagem("numpos", "POSTO NAO CADASTRADO");
				result.include("ctlpc006A", ctlpc006A);
				sessao.setAtributo("CTLPC006", this);
				ctlpc006A.enviarTela(false, result, getClass().getSimpleName().toUpperCase());
				return;
			}
			ctltc006.setPosto(vwTabele.resp);
		} else {
			ctltc006.setPosto("CANCELAMENTO GERAL");
		}
		if (UtilBean.validaSelecao(ctlpc006A.getConimp())) {
			ctlpc006A.enviarMensagem("tidoem", "");
			result.include("ctlpc006A", ctlpc006A);
			sessao.setAtributo("CTLPC006", this);
			ctlpc006A.enviarTela(false, result, getClass().getSimpleName().toUpperCase());
			return;
		}
		ctltc006.setDtini(Integer.parseInt(ctlpc006A.getDatini()));
		ctltc006.setDtini((int) funcoes.sissd002(ctltc006.getDtini()));
		ctltc006.setDtfim(Integer.parseInt(ctlpc006A.getDatfim()));
		ctltc006.setDtfim((int) funcoes.sissd002(ctltc006.getDtfim()));
		if (!ctlpc006A.getConimp(2).trim().equals("")) {
			mostra();
		} else {
			if (ctltc006.getOpc() > 0) {

				if (ctltc006.getConf().equals("N")) {
					ctltc006.enviarMensagem("opc", "NUMERO SELECIONADO INVALIDO");
					sessao.setAtributo("CTLPC006", this);
					result.include("ctltc006", ctltc006);
					ctltc006.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
				}

				i = 14;

				if (ctltc006.getOpc() > i) {
					ctltc006.enviarMensagem("opc", "NUMERO SELECIONADO INVALIDO");
					sessao.setAtributo("CTLPC006", this);
					result.include("ctltc006", ctltc006);
					ctltc006.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
					return;
				}

				saida(pctltc001);

				sessao.setAtributo("CTLPC006", this);
				result.include("ctltc006", ctltc006);
				if (!result.used())
					ctltc006.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
				return;
			}

			while (vwDvecon.pesquisaDataEmissaoFaixa(Integer.parseInt(ctlpc006A.getDatini()), Integer.parseInt(ctlpc006A.getDatfim()))) {
				if (vwDvecon.fimDados()) {
					if (i > 0 && ctltc001.getOperacao().equals("ELD")) {
						//
						if (!saida(pctltc001))
							return;
					}
				}
				cont += 1;
				if (cont > 10) {
					cont = 0;

					// ctlpc006A.enviarReceberTela(false, result);
					// CTLPC006_A
				}
				if (!(vwDvecon.getTipoDocumento() == ctlpc006B.getTidoem() && vwDvecon.getCodigoMunicipio() == ctlpc006A.getNumpos())) {
					continue;
				}
				i += 1;
				ctltc006.setDat(i, vwDvecon.getDataEmissao());
				ctltc006.setDat(i, (int) funcoes.sissd002(ctltc006.getDat(i)));
				chassi = vwDvecon.getNumeroChassi();
				ctltc006.getRg()[i] = Long.parseLong(UtilBean.subStr(chassi, 0, 13));
				nome();
				ctltc006.setMat(i, vwDvecon.getMatriculaFunc());
				ctltc006.setNde(i, vwDvecon.getNumeroDocumento());

				if (vwDvecon.fimDados() || i == 14) {

					saida(pctltc001);
					ctltc006.setMensagemSaida("CONSULTA EFETUADA OK");

					if (vwDvecon.fimDados()) {
						ctltc006.setMensagemSaida("CONSULTA EFETUADA OK");
					}

					break;

				}
				if (ctltc006.getConf().equals("N")) {

					ctlpc006A.setMensagemSaida("CONSULTA INTERROMPIDA OK");
					ctlpc006A.setNavegar("../ctlpc006/executar");
					result.include("ctlpc006A", ctlpc006A);
					sessao.setAtributo("CTLPC006", this);
					ctlpc006A.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
					break;
				}

			}
			if (vwDvecon.registrosProcessados() == 0) {
				ctlpc006A.enviarMensagem(null, "");
				ctlpc006A.setNavegar("../ctlpc006/executar");
				result.include("ctlpc006A", ctlpc006A);
				sessao.setAtributo("CTLPC006", this);
				ctlpc006A.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
				return;
			}
			sessao.setAtributo("CTLPC006", this);
			result.include("ctltc006", ctltc006);
			ctltc006.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
		}
	}

	private boolean saida(Ctltc001 pctltc001) throws Exception {

		ctltc006.receberTela(false, result);
		if (!ctltc001.getOperacao().equals("ELD")) {
			testar();
		}
		if (ctltc006.getOpc() > 0) {
			if (ctltc006.getOpc() > i) {
				ctltc006.enviarMensagem("opc", "NUMERO SELECIONADO INVALIDO");
				return false;
			}
			// do {
			ctltc001.setChave(String.valueOf(ctltc006.getRg()[ctltc006.getOpc()]));
			// vwDvecon2.fecha();
			while (vwDvecon2.leituraNumeroChassiMaiorig(StringUtils.leftPad(ctltc001.getChave(), 13, "0"))) {
				// READADA
				if (!ctltc001(pctltc001)) {
					return false;
				} else {
					return true;
				}
			}
			/*
			 * if (!ctltc001.getChave().trim().equals("")) { break; }
			 */
			// }
			/*
			 * if (ctltc006.getConf().equals("N") && ctltc001.getOperacao().equals("ELD")) { ctltc001.setConf("S");
			 * 
			 * ctltc006.receberTela(false, result); } if (ctltc006.getConf().equals("N")) {
			 * 
			 * ctlpc006A.setMensagemSaida("CONSULTA INTERROMPIDA OK"); return false; }
			 */
			// } while (!(ctltc006.getOpc() == 0));
		}
		i = 0;
		for (int i1 = 1; i1 <= 14; i1++) {
			ctltc006.getRg()[i] = 0;
			nde[i1] = 0;
			ctltc006.setNom(i, "");
			ctltc006.setDat(i, 0);
			mat[i1] = 0;
		}
		if (!ctltc001.getOperacao().equals("ELD")) {
			testar();
		}
		return true;
	}

	private void testar() {
		funcoes.sissm001(result, sessao);
	}

	private void mostra() throws Exception {
		// DEFINE PRINTER(FM = 1)
		report = new Ctltc106Report();
		// ctltc001.setConf("S");
		while (vwDvecon.pesquisaDataEmissaoFaixa(Integer.parseInt(ctlpc006A.getDatini()), Integer.parseInt(ctlpc006A.getDatfim()))) {
			/*
			 * if (vwDvecon.fimDados()) { if (i > 0 && ctltc001.getOperacao().equals("ELD")) { // saida2(); } }
			 */
			cont += 1;
			if (cont > 10) {
				cont = 0;

				// ctlpc006A.enviarReceberTela(false, result);
				// CTLPC006
			}
			if (!(vwDvecon.getTipoDocumento() == ctlpc006B.getTidoem() && vwDvecon.getCodigoMunicipio() == ctlpc006A.getNumpos())) {
				continue;
			}
			i += 1;
			dat1[i] = vwDvecon.getDataEmissao();
			dat1[i] = (int) funcoes.sissd002(dat1[i]);
			report.setDat1(i, dat1[i]);
			chassi = vwDvecon.getNumeroChassi();
			rg1[i] = Long.parseLong(UtilBean.subStr(chassi, 0, 13));
			report.setRg1(i, rg1[i]);
			nome();
			mat1[i] = vwDvecon.getMatriculaFunc();
			report.setMat1(i, mat1[i]);
			nde1[i] = vwDvecon.getNumeroDocumento();
			report.setNde1(i, nde1[i]);
			report.setEmpresa(ctlpc006A.getEmpresa());
			report.setHoraCorrente(ctlpc006A.getHoraCorrente());
			report.setNomeClasse(ctlpc006A.getNomeClasse());
			report.setVersao(ctlpc006A.getVersao());

			ctlpc006A.setMensagemSaida("EMISSAO EFETUADA OK");
			if (i == 50 || vwDvecon.fimDados()) {
				saida2();
				i = 0;
			}

		}
		if (vwDvecon.registrosProcessados() == 0) {
			ctlpc006A.enviarMensagem(null, "N�O ENCONTROU REGISTROS");
			ctlpc006A.setNavegar("../ctlpc006/executar");
			result.include("ctlpc006A", ctlpc006A);
			sessao.setAtributo("CTLPC006", this);
			ctlpc006A.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
			return;
		} else {
			relatorio = report.imprimir();
		}
	}

	private void saida2() throws ParseException, JRException {
		report.gravaRelatorio(1);

		// RELATORIO
		for (int i1 = 1; i1 <= 50; i1++) {
			nom1[i1] = "";
			rg1[i1] = 0;
			mat1[i1] = 0;
			nde1[i1] = 0;
			dat1[i1] = 0;
		}
	}

	private void nome() throws ParseException {
		vwDidcad.consultaNumeroRg(Long.parseLong(UtilBean.subStr(chassi, 0, 13)));
		nom1[i] = vwDidcad.getNomeIdent();
		report.setNom1(i, nom1[i]);
	}

	private void restaurarEstados(Ctlpc006A pctlpc006A, Ctlpc006B pctlpc006B, Ctlpc006C pctlpc006C, Ctlpc006D pctlpc006D, Ctltc001 pctltc001, Ctltc006 pctltc006) {
		this.ctlpc006Anterior = (Ctlpc006) sessao.getAtributo("CTLPC006");
		if (pctlpc006A != null) {
			ctlpc006A = pctlpc006A;
		} else {
			ctlpc006A = this.ctlpc006Anterior.ctlpc006A;
		}
		ctlpc006A.setSessao(sessao);
		if (pctlpc006B != null) {
			ctlpc006B = pctlpc006B;
		} else {
			ctlpc006B = this.ctlpc006Anterior.ctlpc006B;
		}
		ctlpc006B.setSessao(sessao);
		if (pctlpc006C != null) {
			ctlpc006C = pctlpc006C;
		} else {
			ctlpc006C = this.ctlpc006Anterior.ctlpc006C;
		}
		ctlpc006C.setSessao(sessao);
		if (pctlpc006D != null) {
			ctlpc006D = pctlpc006D;
		} else {
			ctlpc006D = this.ctlpc006Anterior.ctlpc006D;
		}
		ctlpc006D.setSessao(sessao);
		if (pctltc001 != null) {
			ctltc001 = pctltc001;
		} else {
			ctltc001 = this.ctlpc006Anterior.ctltc001;
		}
		ctltc001.setSessao(sessao);
		if (pctltc006 != null) {
			ctltc006 = pctltc006;
		} else {
			ctltc006 = this.ctlpc006Anterior.ctltc006;
		}
		ctltc006.setSessao(sessao);
		this.faseproc = this.ctlpc006Anterior.faseproc;
		vwDvecon = this.ctlpc006Anterior.vwDvecon;
		vwDvecon2 = this.ctlpc006Anterior.vwDvecon2;

	}

	public boolean ctltc001(Ctltc001 pctltc001) throws Exception {
		ctltc001.setDatemi(vwDvecon2.getDataEmissao());
		ctltc001.setDatemi(funcoes.sissd002(ctltc001.getDatemi()));
		// INVERTE DATA
		valpago = vwDvecon2.getValorPago();
		vwTabele.pesq = UtilBean.moveSubstring(vwTabele.pesq, 0, 3, "N", 18);
		vwTabele.pesq = UtilBean.moveSubstring(vwTabele.pesq, 3, 12, "N", vwDvecon2.getMatriculaFunc());
		vwTabele.resp = funcoes.sisst001(18, vwDvecon2.getMatriculaFunc(), vwTabele.resp);
		// PESQUISA TABELA
		ctltc001.setNomfun(vwTabele.resp);
		vwTabele.pesq = UtilBean.moveSubstring(vwTabele.pesq, 0, 3, "N", 19);
		vwTabele.pesq = UtilBean.moveSubstring(vwTabele.pesq, 3, 12, "N", vwDvecon2.getTipoDocumento());
		vwTabele.chalfa = funcoes.sisst002(19, vwDvecon2.getTipoDocumento(), vwTabele.chalfa);
		ctltc001.setDiacntchassi(vwDvecon2.getNumeroChassi());
		ctltc001.setDiacntrequer(vwDvecon2.getNomeRequerente());
		ctltc001.setDiacntendere(vwDvecon2.getEnderecoRequerente());
		ctltc001.setDiacntidenti(vwDvecon2.getNumeroIdentidade());
		ctltc001.setDiacntdestin(vwDvecon2.getDestinoSolicitacao());
		ctltc001.setDatemi(Long.valueOf(UtilBean.inverteDataDDMMYYYY(vwDvecon2.getDataEmissao())));
		ctltc001.setTipdoc(vwDvecon2.getTipoDocumento() + "");
		ctltc001.setValpag(vwDvecon2.getValorPago());

		// PESQUISA TABELA
		ctltc001.setTipdoc(vwTabele.chalfa);

		result.include("ctltc001", ctltc001);
		sessao.setAtributo("CTLPC006", this);
		ctltc001.enviarTela(false, result, getClass().getSimpleName().toUpperCase());

		/*
		 * if (pctltc001 != null) { ctltc001.receberTela(false, result); }
		 */
		// TELA CONSULTA DOCUMENTOS EMITIDOS
		if (!(ctltc001.getOperacao().equals("CEC") || ctltc001.getOperacao().equals("CEN") || ctltc001.getOperacao().equals("CED") || ctltc001.getOperacao().equals("CDC") || ctltc001.getOperacao().equals("CDD") || ctltc001.getOperacao().equals("ELD"))) {
			testar();
		}
		if (ctltc006.getConf().equals("N")) {
			return false;
		}
		/*
		 * if (!ctltc001.getChave().trim().equals("")) { return false; } ctltc001.setTipdoc("");
		 */
		return true;
	}
}
